const app = new Vue({
    el: '#app',
    data: {
        tlogSystemVo:new TlogSystemVo(),
        page:{},
        entity:new TlogSystemVo(),
        records:[],
        startIndex:0,
        endIndex:0,
        nowIndex:0,
        currentPageStartIndex:0,
        indexAndIdMap:new Map(),
        /**
         * 级别类型列表， 1：信息，2：警告，3：错误
         */
        levelList:{'1':'信息','2':'警告','3':'错误'},

        logIconImgList:{'1':'logicon_info.gif','2':'logicon_warning.gif','3':'logicon_err.gif'},


    },
    methods: {
        initAttrStr: function (){
            this.tlogSystemVo.levelStr=this.levelList[this.tlogSystemVo.level];
            this.tlogSystemVo.levelImg="/static/img/"+this.logIconImgList[this.tlogSystemVo.level];
            this.tlogSystemVo.actTimeStr=!this.tlogSystemVo.actTime ? '' : rx.dateFormat(new Date(this.tlogSystemVo.actTime), 'yyyy-MM-dd hh:mm:ss');
          //  this.tlogSystemVo.actTime =rx.dateFormat(new Date(this.tlogSystemVo.actTime), 'yyyy-MM-dd hh:mm:ss')

        },
        async  TlogSystemInfo() {
            //this.tlogSystemVo = await tlogOperationApi.getTlogOperationInfobyId(forward.getData().id)

            this.page=forward.getData().page;
            this.currentPageStartIndex=forward.getData().pagestartIndex;
            this.endIndex=forward.getData().endIndex;
            this.entity = forward.getData().entity;
            var id=forward.getData().id;
            this.records = this.page.records;
            for (var i=0;i<this.records.length;i++){
                var nowid=this.records[i].id;
                this.indexAndIdMap.set(this.currentPageStartIndex+i,nowid);
                if(id==nowid){
                    this.nowIndex = this.currentPageStartIndex+i;
                }
            }
            this.tlogSystemVo =this.records[this.nowIndex-this.currentPageStartIndex];
            this.initAttrStr();

        },
        //返回列表
        returnSuper(){
            forward('security-log/admin_security_sysloglist',{
                page:this.page,
                entity:this.entity,
                isfromSub:true,
            });
        },
        //上一页n
        async previousPage(){
            if(this.nowIndex==0){
                rxPrompt.msg('这是第一条数据，没有上一条啦');
                return;
            }
            if(this.nowIndex==this.currentPageStartIndex) {
                //获取记录表上页的数据
                this.page.current--;
                this.page = await tlogSystemApi.page(this.page, this.entity);
                this.records =this.page.records;
                this.currentPageStartIndex=this.currentPageStartIndex-this.page.size;
                for (var i=0;i<this.records.length;i++){
                    var nowid=this.records[i].id;
                    this.indexAndIdMap.set(this.currentPageStartIndex+i,nowid);
                }

            }
            this.nowIndex--;
            this.tlogSystemVo =this.records[this.nowIndex-this.currentPageStartIndex];
            //this.tlogSystemVo = await tlogOperationApi.getTlogOperationInfobyId(this.indexAndIdMap.get(this.nowIndex));
            this.initAttrStr();

        },
        //下一页
        async nextPage(){
            if(this.nowIndex==this.endIndex){
                rxPrompt.msg('这是第最后一条数据，没有下一条啦');
                return;
            }
            if(this.nowIndex==this.currentPageStartIndex+this.page.size-1) {
                //获取记录表上页的数据
                this.page.current++;
                this.page = await tlogSystemApi.page(this.page, this.entity);
                this.records =this.page.records;
                this.currentPageStartIndex=this.currentPageStartIndex+this.page.size;
                for (var i=0;i<this.records.length;i++){
                    var nowid=this.records[i].id;
                    this.indexAndIdMap.set(this.currentPageStartIndex+i,nowid);
                }

            }
            this.nowIndex++;
            this.tlogSystemVo =this.records[this.nowIndex-this.currentPageStartIndex];
            //this.tlogSystemVo= await tlogOperationApi.getTlogOperationInfobyId(this.indexAndIdMap.get(this.nowIndex));
            this.initAttrStr();

        },
    },
    mounted() {
        this.TlogSystemInfo();
    },

})